package com.app.view.component.room 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.SimpleButton;
	import flash.geom.Point;
	import flash.display.DisplayObjectContainer;
	import flash.utils.*;
	
	import com.greensock.TweenLite;
	
	import com.peachcastle.events.SeatEvent;
	import com.peachcastle.core.Display;
	
	import com.app.model.data.UserData;
	
	import com.app.view.component.room.seat.BankerOperate;
	import com.app.view.component.room.seat.PlayrOperate;
	import com.app.view.component.room.seat.PaijiuItem;
	
	import com.peachcastle.tools.Assert;
	
	/**
	 * ...
	 * @author kevin
	 */
	
	[Event(name = "click", type = "flash.events.MouseEvent")]
	public class SeatItem extends Display
	{
		private var _data:UserData = null;
		
		private var _index:int = -1;

		private var _seatInfo:SeatInfo = null;
		private var _paijiuItem:PaijiuItem = null;
		
		private var _bankerOpt:BankerOperate = null;
		private var _playrOpt:PlayrOperate = null;
		
		private var _mc_tip:MovieClip = null;
		private var _mcWinTip:MovieClip = null;
		private var _mcLossTip:MovieClip = null;
		private var _mcGiveupTip:MovieClip = null;
		
		private var _tipsInfo:MovieClip = null;
		
		public function SeatItem(ui:MovieClip = null) 
		{
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			
			//断言
			//Assert.hasNot(assest, 'mc_tip', 'SeatItem');
			Assert.hasNot(assest, 'mc_win_tip', 'SeatItem');
			Assert.hasNot(assest, 'mc_loss_tip', 'SeatItem');
			Assert.hasNot(assest, 'mc_giveup_tip', 'SeatItem');
			Assert.hasNot(assest, 'banker_operation', 'SeatItem');
			Assert.hasNot(assest, 'playr_operation', 'SeatItem');
			Assert.hasNot(assest, 'tipsInfo', 'SeatItem');
			Assert.hasNot(assest, 'seatInfo', 'SeatItem');
			
			_index = parseInt(assest.name.substr(assest.name.length - 1));
			_seatInfo = new SeatInfo(assest['seatInfo']);
			
			_paijiuItem = new PaijiuItem(assest);
			
			//_mc_tip = assest["mc_tip"];
			setTip(false);
			
			_mcWinTip = assest["mc_win_tip"];
			_mcLossTip = assest["mc_loss_tip"];
			_mcGiveupTip = assest["mc_giveup_tip"];
			_tipsInfo = assest["tipsInfo"];
			_tipsInfo.visible = false;
			_tipsInfo.alpha = 0;
			
			setGameStatus('init');
			
			_bankerOpt = new BankerOperate(assest["banker_operation"], _index);
			_playrOpt = new PlayrOperate(assest["playr_operation"], _index);
		}
		
		override protected function configEventListeners():void 
		{
			super.configEventListeners();
			
			_paijiuItem.addEventListener(MouseEvent.CLICK, hideTips)
		}

		public function addPlayer(data:UserData = null):void
		{
			_data = data;
			_seatInfo.addPlayer(data);
		}
		
		public function removePlayer():void
		{
			_seatInfo.removePlayer();
			setGameStatus('init');
			setTip(false);
			_data = null;
			
		}
		
		public function update(data:UserData = null):void
		{
			if (_data)
			{
				_data = data;
				_seatInfo.update(data);
			}
		}
		
		public function startClock(time:int):void
		{
			_seatInfo.clock.start(time);
		}
		
		public function stopClock():void
		{
			_seatInfo.clock.stop();
		}
		
		public function sendCard(mc:MovieClip, seatid:int, cardIndex:int, paijiusData:String, isSelf:Boolean, callback:Function, paisBg:Array, startPositionMc:MovieClip):void
		{
			_paijiuItem.sendCard(mc, seatid, cardIndex, paijiusData, isSelf, callback, paisBg, startPositionMc);
		}
		
		public function showPaijiuValues(cardIndex:int, count:int, data:Array, isSelf:Boolean):void
		{
			_paijiuItem.showValues(cardIndex, count, data, isSelf);
		}
		
		public function changePaijiuStatus(isActive:Boolean):void
		{
			_paijiuItem.changePaijiuStatus(isActive);
		}
		
		public function showResult(data:Array, isShowBig:Boolean):void
		{
			_paijiuItem.showResult(data, isShowBig);
		}
		
		public function setTip(b:Boolean):void
		{
			//_mc_tip.visible = b;
		}
		
		public function setGameStatus(status:String, b:Boolean = false):void
		{
			switch(status)
			{
				case 'win':
					if (_mcWinTip.visible != b) _mcWinTip.visible = b;
					
					break;
					
				case 'loss':
					if (_mcLossTip.visible != b) _mcLossTip.visible = b;
					
					break;
					
				case 'giveup':
					if (_mcGiveupTip.visible != b) _mcGiveupTip.visible = b;
					
					break;
					
				case 'init':
					_mcWinTip.visible = false;
					_mcLossTip.visible = false;
					_mcGiveupTip.visible = false;
					
					break;
			}
		}
		
		public function hidePaijius():void
		{
			_paijiuItem.hidePaijius();
		}
		
		public function getPaijiuPosition():String
		{
			return _paijiuItem.getPaijiuPosition();
		}
		
		public function showTips():void
		{
			_tipsInfo.visible = true;
			TweenLite.to(_tipsInfo, 1.5, {alpha:1});
			
			TweenLite.delayedCall(4, hideTips);
		}
		
		public function hideTips(e:MouseEvent = null):void
		{
			TweenLite.to(_tipsInfo, 1.5, {alpha:0, visible:false});
		}
		
		public function getCenterPos():Point
		{
			return assest.parent.localToGlobal(new Point(assest.x, assest.y));
		}
		
		public function get index():int { return _index; }
		public function get playrOpt():PlayrOperate { return _playrOpt; }
		public function get bankerOpt():BankerOperate { return _bankerOpt; }
	}

}